package com.example.orderservice.service;

import com.example.orderservice.feign.InventoryFeignClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.UUID;

@Service
public class OrderService {

    @Autowired
    private InventoryFeignClient inventoryFeignClient;

    public String createOrder(String productId, Integer count) {
        // 调用库存服务扣减库存
        Boolean result = inventoryFeignClient.deductInventory(productId, count);
        if (result) {
            // 生成订单号
            String orderId = UUID.randomUUID().toString();
            // 这里简化处理，实际项目中可能需要保存订单到数据库
            return "订单创建成功，订单号：" + orderId;
        } else {
            return "订单创建失败，库存不足";
        }
    }
}
    